
from math import inf

class Solution:

    pre = -inf

    def isValidBST(self, root):
        if not root:
            return True
        
        # 判断左子树
        if not self.isValidBST(root.left):
            return False
        
        # 更新
        if root.val <= self.pre:
            return False
        
        self.pre = root.val

        # 判断右子树
        return self.isValidBST(root.right)
